package org.wxq.output;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public class MyWriter {
	
	private String filename;
	private FileWriter fw;
	
	public MyWriter(String filename){
		this.filename = filename;
		init();
	}
	
	private void init(){
		File file = new File(filename);
		if(file.exists()){
			file.delete();
		}
		try {
			file.createNewFile();
			fw = new FileWriter(filename);
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}
	
	public void write(String str) throws IOException{
		fw.write(str);
//		fw.write("\r\n");
	}
	
	public void write(int num) throws IOException{
		fw.write(String.valueOf(num));
	}
	
	public static void main(String[] args){
		MyWriter writer = new MyWriter("d:/test.txt");
		try {
			writer.write("test");
//			writer.fw.close();
			writer.write("test2");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void close(){
		try {
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void flush() {
		try {
			fw.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


}
